package com.android.phoenix.activity.location;

import java.util.ArrayList;
import java.util.List;
import com.android.phoenix.Constant;
import com.android.phoenix.R;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.CityInfo;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener;
import com.baidu.mapapi.search.sug.SuggestionResult;
import com.baidu.mapapi.search.sug.SuggestionSearch;
import com.baidu.mapapi.search.sug.SuggestionSearchOption;
import com.baidu.navisdk.BaiduNaviManager;
import com.baidu.navisdk.BNaviEngineManager.NaviEngineInitListener;
import com.baidu.navisdk.CommonParams.NL_Net_Mode;
import com.baidu.navisdk.CommonParams.Const.ModelName;
import com.baidu.navisdk.comapi.mapcontrol.BNMapController;
import com.baidu.navisdk.comapi.mapcontrol.MapParams.Const.LayerMode;
import com.baidu.navisdk.comapi.routeguide.RouteGuideParams.RGLocationMode;
import com.baidu.navisdk.comapi.routeplan.BNRoutePlaner;
import com.baidu.navisdk.comapi.routeplan.IRouteResultObserver;
import com.baidu.navisdk.comapi.routeplan.RoutePlanParams.NE_RoutePlan_Mode;
import com.baidu.navisdk.model.NaviDataEngine;
import com.baidu.navisdk.model.RoutePlanModel;
import com.baidu.navisdk.model.datastruct.RoutePlanNode;
import com.baidu.navisdk.model.datastruct.RoutePlanResultItem;
import com.baidu.navisdk.ui.routeguide.BNavConfig;
import com.baidu.navisdk.ui.routeguide.BNavigator;
import com.baidu.navisdk.ui.widget.RoutePlanObserver;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SportLocationActivity extends Activity {
	private ImageView title_Imgbtn_left_up;
	private TextView title_txt_center;
	private TextView title_txt_right_up;
	private AutoCompleteTextView AutoCom_terminate;
	private TextView txt_my_location;
	private ListView list_sport_location;
	private ImageView btn_location_terminal_serch;
	private List<String> listLocationData = new ArrayList<String>();
	private locationAdapter mListAdapter;
	private LocationClient locationClient;
	private int startX = 0;
	private int startY = 0;
	private List<LatLng> listLatLng = new ArrayList<LatLng>();
	private int index = 0;

	private ArrayList<RoutePlanNode> nodeList = new ArrayList<RoutePlanNode>(2);
	// 查询终点
	private PoiSearch mPoiSearch = null;
	// 建议搜索结果
	private SuggestionSearch mSuggestionSearch = null;
	private ArrayAdapter<String> sugAdapter = null;
	// 规划路线控制面板
	private RoutePlanModel mRoutePlanModel = null;

	private static final int UPDATE_DATA = 1;
	private static final int UPDATE_LOCATION_STRING = 2;
	private static final int ITEM_CLICK = 3;

	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case UPDATE_DATA:
				list_sport_location.setAdapter(mListAdapter);
				break;

			case UPDATE_LOCATION_STRING:
				if (msg.obj == null) {
					Toast.makeText(SportLocationActivity.this, "请检查网络！", 1)
							.show();
					return;
				}
				txt_my_location.setText("我的位置:" + (String) msg.obj);
				break;
			case ITEM_CLICK:
				AutoCom_terminate.setText(listLocationData.get(index));
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acti_sport_location);
		// 初始化View
		initView();
		// 初始化titleBar
		initTitleBar();
		// initSerch注册检索
		initSerch();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// 初始化导航工具
		initForNavi();
		initLocation();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		BNRoutePlaner.getInstance().setRouteResultObserver(null);
		super.onPause();
	}

	private void initView() {
		// TODO Auto-generated method stub
		txt_my_location = (TextView) this.findViewById(R.id.txt_my_location);
		txt_my_location.setOnClickListener(new serchClickListener());

		AutoCom_terminate = (AutoCompleteTextView) this
				.findViewById(R.id.AutoCom_terminate);
		list_sport_location = (ListView) this
				.findViewById(R.id.list_sport_location);
		btn_location_terminal_serch = (ImageView) this
				.findViewById(R.id.btn_location_terminal_serch);
		btn_location_terminal_serch
				.setOnClickListener(new serchClickListener());
		mListAdapter = new locationAdapter(SportLocationActivity.this,
				listLocationData);
		list_sport_location.setOnItemClickListener(new listItemClickLister());

	}

	private class listItemClickLister implements OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> arg0, View view, int position,
				long arg3) {
			// TODO Auto-generated method stub
			index = position;
			Message msg = Message.obtain();
			msg.what = ITEM_CLICK;
			handler.sendMessage(msg);
		}

	}

	/**
	 * 
	 * @Title: initTitleBar
	 * @Description: TODO(设置统一的titleBar)
	 * @author: wWX230766
	 * @date: 2015-1-6 下午10:00:48
	 */
	private void initTitleBar() {
		title_Imgbtn_left_up = (ImageView) this
				.findViewById(R.id.title_Imgbtn_left_up);
		title_Imgbtn_left_up.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		title_txt_center = (TextView) this.findViewById(R.id.title_txt_center);
		title_txt_center.setText(R.string.label_sport_navi);
		title_txt_right_up = (TextView) this
				.findViewById(R.id.title_txt_right_up);
		title_txt_right_up.setText(R.string.label_sport_serch);
		title_txt_right_up.setOnClickListener(new serchClickListener());

	}

	/**
	 * 
	 * @Title: initLocation
	 * @Description: TODO(初始化地图定位所需要的配置)
	 * @author: 汪雷
	 * @date: 2014-12-26 下午4:04:52
	 */
	private void initLocation() {
		locationClient = new LocationClient(this);
		locationClient.registerLocationListener(new MyBaiduLocationListener());
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true);// 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setScanSpan(10000);// 设置定位间隔10秒
		option.setIsNeedAddress(true);
		// 设置仅设备(Gps)模式
		option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
		option.setLocationNotify(true);
		// 设置定位选项
		locationClient.setLocOption(option);
		// 启动定位
		locationClient.start();
	}

	/**
	 * 
	 * @ClassName: MyBaiduLocationListener
	 * @Description: TODO(定位后回调接口)
	 * @author: MyBaiduLocationListener
	 * @date: 2014-12-26 下午4:10:06
	 */
	private class MyBaiduLocationListener implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			// TODO Auto-generated method stub
			if (location == null) {
				locationClient.stop();
				return;
			}
			Message msg = Message.obtain();
			msg.obj = location.getAddrStr();
			msg.what = UPDATE_LOCATION_STRING;
			handler.sendMessage(msg);
			Log.i("wanglei", "getAddrStr-->" + location.getAddrStr());
			Log.i("wanglei", "getCity-->" + location.getCity());
			Log.i("wanglei", "getDistrict-->" + location.getDistrict());
			Log.i("wanglei", "getStreet-->" + location.getStreet());
			Log.i("wanglei", "getStreetNumber-->" + location.getStreetNumber());
			startX = (int) (location.getLatitude() * 100000);
			startY = (int) (location.getLongitude() * 100000);
			locationClient.stop();

		}

		public void onReceivePoi(BDLocation location) {
			// TODO Auto-generated method stub
		}
	}

	private class serchClickListener implements OnClickListener {

		@Override
		public void onClick(View view) {
			// TODO Auto-generated method stub
			switch (view.getId()) {
			case R.id.btn_location_terminal_serch:
				if ("".equals(AutoCom_terminate.getText())) {
					Toast.makeText(SportLocationActivity.this, "请输入终点", 1)
							.show();
				} else {

					Toast.makeText(SportLocationActivity.this, "查找终点信息", 1)
							.show();

					mPoiSearch.searchInCity((new PoiCitySearchOption()).city(
							"中国").keyword(
							AutoCom_terminate.getText().toString()));
				}
				break;

			case R.id.txt_my_location:
				initLocation();
				break;
			case R.id.title_txt_right_up:
				if (("".equals(AutoCom_terminate.getText()))
						|| ("".equals(txt_my_location.getText()))
						|| listLatLng.size() == 0) {

					Toast.makeText(SportLocationActivity.this, "请请输入位置", 1)
							.show();
					return;
				}

				LocationUtils gps = new LocationUtils();
				if (gps.isGpsEnable(SportLocationActivity.this)) {
					startCalcRoute(NL_Net_Mode.NL_Net_Mode_OnLine);
					naviDialog();
				} else {
					dialog();
				}

				break;
			}
		}

		private void naviDialog() {
			// TODO Auto-generated method stub
			AlertDialog.Builder builder = new Builder(
					SportLocationActivity.this);
			builder.setMessage("开启旅程吧！！");
			builder.setTitle("提示");
			builder.setPositiveButton("确认",
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int arg1) {
							// TODO Auto-generated method stub
							// 打开设置GPS界面
							startNavi(true);
							dialog.dismiss();
						}
					});
			builder.create().show();
		}

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		// if (locationClient.isStarted() && locationClient != null) {
		// locationClient.stop();
		// }
		mPoiSearch.destroy();
		mSuggestionSearch.destroy();
		super.onDestroy();
	}

	private class locationAdapter extends BaseAdapter {
		LayoutInflater layoutInflater;
		Context context;
		ViewHolder viewHolder = null;
		List<String> locationListStr = new ArrayList<String>();

		public locationAdapter(Context context, List<String> locationListStr) {
			this.context = context;
			this.locationListStr = locationListStr;
			layoutInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return locationListStr.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return locationListStr.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View view, ViewGroup viewGroup) {
			// TODO Auto-generated method stub
			if (view == null) {
				viewHolder = new ViewHolder();
				view = layoutInflater.inflate(
						R.layout.list_item_sport_location, null);
				viewHolder.txt_list_item = (TextView) view
						.findViewById(R.id.list_item_my_location);
				view.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) view.getTag();
			}
			viewHolder.txt_list_item.setText(locationListStr.get(position));
			return view;
		}
	}

	class ViewHolder {
		TextView txt_list_item;
	}

	/**
	 * 
	 * @Title: initSuggestSerch
	 * @Description: TODO(注册检索)
	 * @author: wWX230766
	 * @date: 2015-1-7 下午5:49:54
	 */
	private void initSerch() {
		// 初始化搜索模块，注册搜索事件监听
		mPoiSearch = PoiSearch.newInstance();
		mPoiSearch
				.setOnGetPoiSearchResultListener(new mOnGetPoiSearchResultListener());
		mSuggestionSearch = SuggestionSearch.newInstance();
		mSuggestionSearch
				.setOnGetSuggestionResultListener(new mOnGetSuggestionResultListener());

		sugAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line);
		AutoCom_terminate.setAdapter(sugAdapter);

		/**
		 * 当输入关键字变化时，动态更新建议列表
		 */
		AutoCom_terminate.addTextChangedListener(new TextWatcher() {

			@Override
			public void afterTextChanged(Editable arg0) {

			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,
					int arg2, int arg3) {

			}

			@Override
			public void onTextChanged(CharSequence cs, int arg1, int arg2,
					int arg3) {
				if (cs.length() <= 0) {
					return;
				}
				/**
				 * 使用建议搜索服务获取建议列表，结果在onSuggestionResult()中更新
				 */
				mSuggestionSearch
						.requestSuggestion((new SuggestionSearchOption())
								.keyword(cs.toString()).city("中国"));
			}
		});
	}

	/**
	 * 
	 * @ClassName: mOnGetPoiSearchResultListener
	 * @Description: TODO(检索结果监听)
	 * @author: mOnGetPoiSearchResultListener
	 * @date: 2015-1-7 下午5:51:24
	 */
	private class mOnGetPoiSearchResultListener implements
			OnGetPoiSearchResultListener {

		@Override
		public void onGetPoiDetailResult(PoiDetailResult result) {
			// TODO Auto-generated method stub
			if (result.error != SearchResult.ERRORNO.NO_ERROR) {
				Toast.makeText(SportLocationActivity.this, "抱歉，只能搜索当地城市！",
						Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(SportLocationActivity.this,
						result.getName() + ": " + result.getAddress(),
						Toast.LENGTH_SHORT).show();
			}
		}

		@Override
		public void onGetPoiResult(PoiResult result) {
			// TODO Auto-generated method stub
			if (result == null
					|| result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
				Toast.makeText(SportLocationActivity.this, "未找到结果",
						Toast.LENGTH_LONG).show();
				Log.i("wanglei", "-未找到结果-->");
				return;
			}
			if (result.error == SearchResult.ERRORNO.NO_ERROR) {
				listLocationData.clear();
				listLatLng.clear();
				for (int i = 0; i < result.getAllPoi().size(); i++) {

					// 记录点击的listitem的经纬度
					listLatLng.add(result.getAllPoi().get(i).location);
					// 给listview添加数据
					listLocationData.add(result.getAllPoi().get(i).name);
					Message msg = Message.obtain();
					msg.what = UPDATE_DATA;
					handler.sendMessage(msg);

				}

				return;
			}
			if (result.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {

				// 当输入关键字在本市没有找到，但在其他城市找到时，返回包含该关键字信息的城市列表
				String strInfo = "在";
				for (CityInfo cityInfo : result.getSuggestCityList()) {
					strInfo += cityInfo.city;
					strInfo += ",";
				}
				strInfo += "找到结果";
				Toast.makeText(SportLocationActivity.this, strInfo,
						Toast.LENGTH_LONG).show();
			}
		}
	}

	/**
	 * 
	 * @ClassName: mOnGetSuggestionResultListener
	 * @Description: TODO(建议位置)
	 * @author: mOnGetSuggestionResultListener
	 * @date: 2015-1-7 下午5:52:00
	 */
	private class mOnGetSuggestionResultListener implements
			OnGetSuggestionResultListener {

		@Override
		public void onGetSuggestionResult(SuggestionResult res) {
			// TODO Auto-generated method stub
			if (res == null || res.getAllSuggestions() == null) {
				return;
			}
			sugAdapter.clear();
			for (SuggestionResult.SuggestionInfo info : res.getAllSuggestions()) {
				if (info.key != null)
					sugAdapter.add(info.key);
			}
			sugAdapter.notifyDataSetChanged();
		}

	}

	/**
	 * 
	 * @Title: dialog
	 * @Description: TODO(设置高精度定位)
	 * @author: wWX230766
	 * @date: 2014-12-29 下午5:22:42
	 * @param option
	 */
	protected void dialog() {
		AlertDialog.Builder builder = new Builder(SportLocationActivity.this);
		builder.setMessage("设置高精度定位（必须开启gps）");
		builder.setTitle("提示");
		builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int arg1) {
				// TODO Auto-generated method stub
				// 打开设置GPS界面
				Intent intent = new Intent(
						Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				startActivityForResult(intent, 0);
				dialog.dismiss();
			}
		});
		builder.create().show();
	}

	/**
	 * 
	 * @Title: initForNavi
	 * @Description: TODO(以下代码全部是为导航做初始化操作)
	 * @author: wanglei
	 * @date: 2015年1月11日 下午11:27:54
	 */
	private void initForNavi() {
		BaiduNaviManager.getInstance().initEngine(this, getSdcardDir(),
				mNaviEngineInitListener, null);
	}

	private String getSdcardDir() {
		if (Environment.getExternalStorageState().equalsIgnoreCase(
				Environment.MEDIA_MOUNTED)) {
			return Environment.getExternalStorageDirectory().toString();
		}
		return null;
	}

	private NaviEngineInitListener mNaviEngineInitListener = new NaviEngineInitListener() {
		public void engineInitSuccess() {
			Log.i("wanglei", "规划路径初始化成功");
		}

		public void engineInitStart() {
		}

		public void engineInitFail() {
		}
	};

	/**
	 * 
	 * @Title: startCalcRoute
	 * @Description: TODO(以下函数全是用算路使用)
	 * @author: wWX230766
	 * @date: 2015-1-12 下午3:32:35
	 * @param netmode
	 */
	private void startCalcRoute(int netmode) {

		int sX = startX, sY = startY, eX = (int) (listLatLng.get(index).latitude * 100000), eY = (int) (listLatLng
				.get(index).longitude * 100000);
		// try {
		// sX = Integer.parseInt(startXEditText.getText().toString());
		// sY = Integer.parseInt(startYEditText.getText().toString());
		// eX = Integer.parseInt(endXEditText.getText().toString());
		// eY = Integer.parseInt(endYEditText.getText().toString());
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		Log.i("wanglei", "sX--->" + sX);
		Log.i("wanglei", "sY--->" + sY);
		Log.i("wanglei", "eX--->" + eX);
		Log.i("wanglei", "eY--->" + eY);

		RoutePlanNode startNode = new RoutePlanNode(sX, sY,
				RoutePlanNode.FROM_MAP_POINT, "起点", "起点");
		// 终点
		RoutePlanNode endNode = new RoutePlanNode(eX, eY,
				RoutePlanNode.FROM_MAP_POINT, "终点", "终点");
		// 将起终点添加到nodeList
		Log.i("wanglei", "33--->");
		nodeList.clear();
		nodeList.add(startNode);
		nodeList.add(endNode);
		Log.i("wanglei", "55--->");
		// 先确定设置的observer为空
		BNRoutePlaner.getInstance().setObserver(null);

		BNRoutePlaner.getInstance().setObserver(
				new RoutePlanObserver(this, null));
		// 设置算路方式
		BNRoutePlaner.getInstance().setCalcMode(
				NE_RoutePlan_Mode.ROUTE_PLAN_MOD_MIN_TIME);
		// 设置算路结果回调
		BNRoutePlaner.getInstance()
				.setRouteResultObserver(mRouteResultObserver);
		// 设置起终点并算路
		boolean ret = BNRoutePlaner.getInstance().setPointsToCalcRoute(
				nodeList, NL_Net_Mode.NL_Net_Mode_OnLine);

		if (!ret) {
			Toast.makeText(this, "规划失败", Toast.LENGTH_SHORT).show();
		}
	}

	private void startNavi(boolean isReal) {
		ArrayList<String> listRouteDesNodes = new ArrayList<String>();
		if (mRoutePlanModel == null) {
			Toast.makeText(this, "请重新点击搜索！！！", Toast.LENGTH_LONG).show();
			return;
		}
		// 获取路线规划结果起点
		RoutePlanNode startNode = mRoutePlanModel.getStartNode();
		// 获取路线规划结果终点
		RoutePlanNode endNode = mRoutePlanModel.getEndNode();
		Log.i("wanglei ",
				"getTotalDistanceInt()-->"
						+ mRoutePlanModel.getTotalDistanceInt());
		Log.i("wanglei ", "getDistance()-->" + mRoutePlanModel.getDistance());

		if (null == startNode || null == endNode) {
			return;
		}
		//
		List<RoutePlanResultItem> listRoutes = new ArrayList<RoutePlanResultItem>();
		listRoutes = mRoutePlanModel.getRouteNodeData();
		if (listRoutes != null) {
			for (int i = 0; i < listRoutes.size(); i++) {
				listRouteDesNodes.add(listRoutes.get(i).getNodeDesc());
				Log.i("wanglei ", "getNodeDesc()-->"
						+ listRoutes.get(i).getNodeDesc());
				Log.i("wanglei ", "getNodeDescNight()-->"
						+ listRoutes.get(i).getNodeDescNight());
			}
		} else {
			Log.i("wanglei ", "listRoutes-->为null");
		}
		// 获取路线规划算路模式
		int calcMode = BNRoutePlaner.getInstance().getCalcMode();
		Bundle bundle = new Bundle();
		//
		if (listRouteDesNodes.size() > 0) {
			bundle.putStringArrayList("nodes", listRouteDesNodes);
		}

		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_VIEW_MODE,
				BNavigator.CONFIG_VIEW_MODE_INFLATE_MAP);
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_CALCROUTE_DONE,
				BNavigator.CONFIG_CLACROUTE_DONE);
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_START_X,
				startNode.getLongitudeE6());
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_START_Y,
				startNode.getLatitudeE6());
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_END_X, endNode.getLongitudeE6());
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_END_Y, endNode.getLatitudeE6());
		bundle.putString(BNavConfig.KEY_ROUTEGUIDE_START_NAME,
				mRoutePlanModel.getStartName(this, false));
		bundle.putString(BNavConfig.KEY_ROUTEGUIDE_END_NAME,
				mRoutePlanModel.getEndName(this, false));
		bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_CALCROUTE_MODE, calcMode);
		if (!isReal) {
			// 模拟导航
			bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_LOCATE_MODE,
					RGLocationMode.NE_Locate_Mode_RouteDemoGPS);
		} else {
			// GPS 导航
			bundle.putInt(BNavConfig.KEY_ROUTEGUIDE_LOCATE_MODE,
					RGLocationMode.NE_Locate_Mode_GPS);
		}

		Intent intent = new Intent(SportLocationActivity.this,
				SportNaviActivity.class);
		intent.putExtras(bundle);
		startActivity(intent);

		/**
		 * 发送开启导航广播
		 */
		Intent broadcastIntent = new Intent(Constant.START_NAVI_BROADCAST);
		sendBroadcast(broadcastIntent);
	}

	private IRouteResultObserver mRouteResultObserver = new IRouteResultObserver() {

		@Override
		public void onRoutePlanYawingSuccess() {
			// TODO Auto-generated method stub

		}

		@Override
		public void onRoutePlanYawingFail() {
			// TODO Auto-generated method stub

		}

		@Override
		public void onRoutePlanSuccess() {
			// TODO Auto-generated method stub
			BNMapController.getInstance().setLayerMode(
					LayerMode.MAP_LAYER_MODE_ROUTE_DETAIL);
			mRoutePlanModel = (RoutePlanModel) NaviDataEngine.getInstance()
					.getModel(ModelName.ROUTE_PLAN);
		}

		@Override
		public void onRoutePlanFail() {
			// TODO Auto-generated method stub
		}

		@Override
		public void onRoutePlanCanceled() {
			// TODO Auto-generated method stub
		}

		@Override
		public void onRoutePlanStart() {
			// TODO Auto-generated method stub

		}

	};
}
